package com.hegongda.dao.impl;

import com.hegongda.bean.EChar;
import com.hegongda.dao.ECharDao;
import com.hegongda.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import java.sql.SQLException;
import java.util.List;

public class ECharDaoImpl implements ECharDao {
    @Override
    public List<EChar> fundThisYear() throws SQLException {
        //SELECT * FROM `orders` WHERE  YEAR(ordertime)=YEAR(NOW()) AND MONTH(ordertime)=6
        QueryRunner qr = new QueryRunner(JdbcUtils.getDataSource());
        String sql = "SELECT SUM(total) AS totalCount,state, MONTH(ordertime) AS mon FROM `orders` GROUP BY state ,MONTH(ordertime)";
        List<EChar> query = qr.query(sql, new BeanListHandler<EChar>(EChar.class));
        return query;
    }
}
